from gui import gui
from gui . tests . create_widget_test_assistant import gui_create_widget_test_assistant

class application_window_fake :
    pass

class entry_fake :
    _call_history = [ ]
    def __init__ ( self , textvariable ) :
        self . _received_icursor_args = [ ]
        self . _destroyed = False
        textvariable . _owner_class = entry_fake
    def icursor ( self , index ) :
        entry_fake . _call_history += [ entry_fake . icursor ]
        self . _received_icursor_args = [ index ]
    def destroy ( self ) :
        self . _destroyed = True

class string_var_fake :
    def __init__ ( self ) :
        self . _text = None
    def set ( self , text ) :
        self . _owner_class . _call_history += [ string_var_fake . set ]
        self . _text = text
    def get ( self ) :
        return self . _text

class tkinter_fake :
    def __init__ ( self ) :
        self . _entry_collection = [ ]
        self . END = None
    def Tk ( self ) :
        return application_window_fake ( )
    def Entry ( self , master , _fake_arg = None , borderwidth = None , textvariable = None ) :
        entry = entry_fake ( textvariable )
        self . _entry_collection += [ entry ]
        return entry
    def StringVar ( self ) :
        return string_var_fake ( )

class mediator_fake :
    def __init__ ( self ) :
        self . _gui_create_application_window_reply = None
        self . _gui_create_entry_reply = None
        self . _gui_entry_text_reply = None
    def gui_create_application_window_reply ( self , window ) :
        self . _gui_create_application_window_reply = window
    def gui_create_entry_reply ( self , entry ) :
        self . _gui_create_entry_reply = entry
    def gui_entry_text_reply ( self , text ) :
        self . _gui_entry_text_reply = text 

class gui_entry_tests :
    'gui_entry'
    def __init__ ( self , test ) :
        self . _assistant = gui_create_widget_test_assistant ( test )
        self . _test = test
        self . _tkinter = tkinter_fake ( )
        self . _mediator = mediator_fake ( )
        self . _gui = gui ( mediator = self . _mediator , tkinter = self . _tkinter , tkfont = None , scheduler = None )
        entry_fake . _call_history = [ ]
    def test_gui_create_entry ( self ) :
        self . _assistant . check_gui_create_arbitrary_element ( 'entry' , None )
    def test_gui_create_entry_string_var ( self ) :
        self . _assistant . check_gui_create_arbitrary_element_string_var ( 'entry' , None )
    def test_gui_create_entry_args ( self ) :
        self . _assistant . check_gui_create_arbitrary_element_args_with_string_var ( 'entry' , 'my borderwidth' )
    def test_gui_create_entry_string_var_persistance ( self ) :
        self . _assistant . check_gui_create_arbitrary_element_string_var_persistance ( 'entry' , None )
    def test_gui_create_entry_string_var_destruction ( self ) :
        self . _assistant . check_gui_create_arbitrary_element_string_var_destruction ( 'entry' , None )
    def test_gui_create_entry_persistance ( self ) :
        self . _assistant . check_gui_create_arbitrary_element_persistance ( 'entry' , None )
    def test_gui_create_entry_destruction ( self ) :
        self . _assistant . check_gui_create_arbitrary_element_destruction ( 'entry' , None )
    def test_gui_create_entry_child ( self ) :
        self . _assistant . check_gui_create_arbitrary_element_child ( 'entry' , None )
    def test_gui_set_entry_text ( self ) :
        self . _assistant . check_gui_set_arbitrary_element_text ( 'entry' , None )
    def test_gui_entry_text ( self ) :
        self . _gui . gui_create_application_window_request ( )
        window = self . _mediator . _gui_create_application_window_reply
        self . _gui . gui_create_entry_request ( window , None )
        entry = self . _mediator . _gui_create_entry_reply
        self . _gui . gui_set_entry_text ( entry , 'my text' )
        self . _gui . gui_entry_text_request ( entry )
        self . _test . assume_equal ( self . _mediator . _gui_entry_text_reply , 'my text' )
    def test_gui_set_entry_text_cursor_to_the_end ( self ) :
        self . _gui . gui_create_application_window_request ( )
        window = self . _mediator . _gui_create_application_window_reply
        self . _gui . gui_create_entry_request ( window , None )
        entry = self . _mediator . _gui_create_entry_reply
        self . _tkinter . END = 'my end'
        self . _gui . gui_set_entry_text ( entry , None )
        self . _test . assume_equal ( self . _tkinter . _entry_collection [ 0 ] . _received_icursor_args , [ 'my end' ] )
    def test_gui_set_entry_text_calling_order ( self ) :
        self . _gui . gui_create_application_window_request ( )
        window = self . _mediator . _gui_create_application_window_reply
        self . _gui . gui_create_entry_request ( window , None )
        entry = self . _mediator . _gui_create_entry_reply
        self . _gui . gui_set_entry_text ( entry , None )
        self . _test . assume_equal ( entry_fake . _call_history ,
            [ string_var_fake . set
            , entry_fake . icursor
            ] )
    def test_gui_destroy_entry ( self ) :
        self . _gui . gui_create_application_window_request ( )
        window = self . _mediator . _gui_create_application_window_reply
        self . _gui . gui_create_entry_request ( window , None )
        entry = self . _mediator . _gui_create_entry_reply
        self . _gui . gui_destroy_entry ( entry )
        self . _test . assume_true ( self . _tkinter . _entry_collection [ 0 ] . _destroyed )
